<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <table class="layui-hide" id="table-page" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <{if AdminUsersModel::check_right("$module/$controller/save")}>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">新建管理菜单</button>
                <{/if}>
            </div>
        </script>
        <script type="text/html" id="currentTableFilter">
            {{# if (d.parentid == 0) { }}
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="add_son">添加下级</a>
            {{# } }}
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>

    </div>
</div>

<script type="text/javascript">
    layui.use(['form', 'table', 'miniPage', 'element'], function () {
        var table = layui.table;
        var miniPage = layui.miniPage;
        table.render({
            elem: '#table-page'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: ['filter', 'exports']
            , url: '/<{$module}>/<{$controller}>/index?do=list&isajax=1'
            , limit: 30
            , height: 'full-150'//一行条件
            , cols: [[
                {field: 'id', width: 60, title: 'ID', sort: true}
                , {field: 'title', title: '菜单名称', width: 200}
                , {field: 'url', title: 'URL地址', width: 250}
                , {field: 'icon', title: 'icon', width: 200}
                , {field: 'sort', title: '权重', width: 60}
                , {align: 'left', fixed: 'right', toolbar: '#currentTableFilter'}
            ]]
            , page: true
        });

        var $ = layui.$, active = {
            add_son: function (obj) { //获取选中数据
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save/pid/' + data.id);
                var index = layer.open({
                    type: 1
                    , title: '编辑'
                    , content: content
                    , maxmin: true
                    , area: ['60%', '90%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        layero.find("#form-submit").click();
                    }
                });
            },
            edit: function (obj) { //获取选中数据
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save/id/' + data.id);
                var index = layer.open({
                    type: 1
                    , title: '编辑'
                    , content: content
                    , maxmin: true
                    , area: ['60%', '90%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        layero.find("#form-submit").click();
                    }
                });
            }
            , del: function (obj) {
                var data = obj.data;
                layer.confirm('确定需要删除吗?', function (index) {
                    $.post('/<{$module}>/<{$controller}>/del/id/' + data.id + '?isajax=1&', {}, function (res) {
                        layer.msg(res.msg);
                    }, 'json');
                    table.reload('table-page');
                    layer.close(index);
                });
            }
            , add: function () {
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save');
                var index = layer.open({
                    type: 1
                    , title: '新增'
                    , content: content
                    , maxmin: true
                    , area: ['60%', '90%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        layero.find("#form-submit").click();
                    }
                });
            }
        };
        //监听工具条
        table.on('tool(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
        table.on('toolbar(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
    });
</script> 